package com.tieunguyen.truyencuoi;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class DetailActivity extends ActionBarActivity{

	Bundle bundle = new Bundle();
	int storyId;
	String title;
	String detail;
	WebView webview;
	ProgressBar progressBar;
	ProgressDialog progressDialog;
	Handler mHandler = new Handler();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.story_detail);
		bundle = getIntent().getExtras();
		if(bundle != null){
			storyId = bundle.getInt("storyId");
			title = bundle.getString("title");
			detail = bundle.getString("detail");
		}
		webview = (WebView)findViewById(R.id.webview);
		progressBar = (ProgressBar)findViewById(R.id.progress_bar);
		mHandler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				progressBar.setVisibility(View.GONE);
			}
		}, 200);
		String html = getHTML(storyId, title, detail);
		webview.loadDataWithBaseURL("", html, "text/html", "utf-8", null);
		
	}
	
	public String getHTML(int storyId, String title, String content){

		String html = "<html><head><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\" />"
					+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
					+ "<style type=\"text/css\" rel=\"stylesheet\">"
					+ "body {font-family: arial, helvetica, sans-serif;}"
					+ "h2 {font-size: 1.5em;}"
					+ ".item{background: none repeat scroll 0 0 #F6F6F4; width: auto;margin-top: 10px; position: relative; border: 1px solid #eee; border-radius: 10px;-webkit-margin-before: 0.83em;-webkit-margin-after: 0.83em;-webkit-margin-start: 0px;}"
					+ "	.detail{ padding: 0 0 0 10px; text-align: justify; margin: 0; color: #555; line-height: 1.5; font-size: medium; background: #fff;}"
					+ "	.title{font-size: 12px;color: #5C5B5B;padding-left: 10px;}"
					+ "</style>"
					+ "<head><body>"
					+ "<div class=\"item\"><div class=\"title\">"
					+ "<h2>"
					+ title
					+ "</h2>"
					+ "<div class=\"detail\">"
					+ content
					+ "</div>"
					+ "</div>"
					+ "</body></html>";
		return html;
	}

}
